import {defineConfig, loadEnv} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";
import vueDevTools from "vite-plugin-vue-devtools";
import UniComponents from "@uni-helper/vite-plugin-uni-components";
import { NutResolver } from "nutui-uniapp";

// https://vitejs.dev/config/
export default defineConfig(({mode})=>{
  const env = loadEnv(mode, process.cwd(), "");
  return{
    plugins: [
      UniComponents({
        resolvers: [
          NutResolver()
        ]
      }),
      uni(),
      env.VITE_DEVTOOLS === "true"?vueDevTools():[]
    ],
    build:{
      target: "ES2015"
    },
    server:{
      port: parseInt(env.VITE_PORT)||5173,
    },
    base:env.VITE_APP_TITLE,
    css:{
      preprocessorOptions: {
        scss: {
          silenceDeprecations: ["import","color-functions","legacy-js-api"]
        }
      }
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"), // 确保别名'@'指向src目录
      },
    }
  };
});
